package com.example.unisys.controller;


import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.alibaba.fastjson.TypeReference;
import com.example.unisys.common.Response;
import com.example.unisys.common.STATUS;
import com.example.unisys.dao.StuExamMapper;
import com.example.unisys.entity.*;
import com.example.unisys.service.*;
import com.example.unisys.utils.*;
import org.apache.commons.codec.digest.DigestUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpEntity;
import org.springframework.http.HttpHeaders;
import org.springframework.http.ResponseEntity;
import org.springframework.util.LinkedMultiValueMap;
import org.springframework.util.MultiValueMap;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.client.RestTemplate;
import org.springframework.web.multipart.MultipartFile;

import javax.servlet.http.HttpServletRequest;
import java.io.File;
import java.io.FileInputStream;
import java.text.SimpleDateFormat;
import java.util.*;

@RestController
@RequestMapping(value = "/apis/v1/frontend", produces = "application/json; charset=utf-8")
public class FrontendController {

    private static String verifyurl = "https://aip.baidubce.com/rest/2.0/face/v1/faceliveness/verify";

    private static String matchurl = "https://aip.baidubce.com/rest/2.0/face/v3/match";

    private static String polyToken = "https://hls.videocc.net/service/v1/token";

    @Autowired
    SchoolService schoolService;

    @Autowired
    StudentService studentService;

    @Autowired
    StuCourseService stuCourseService;

    @Autowired
    NoticeService noticeService;


    @Autowired
    ExaminationService examinationService;

    @Autowired
    StuExamMapper stuExamMapper;

    @Autowired
    IpService ipService;


    /*
     * 登录
     * */
    @RequestMapping(value = "/login", method = {RequestMethod.POST})
    public Response login(@RequestBody JSONObject jsonParam) {
        HashMap<String, Object> params = JSONObject.parseObject(jsonParam.toJSONString(), new TypeReference<HashMap<String, Object>>() {
        });
        String username = ((String) params.get("username")).trim();
        String tmpPwd = (String) params.get("password");
        Student student = studentService.getByUsername(username);
        if (student == null) return Response.builder().status(STATUS.BAD_REQUEST).message("用户名密码不匹配").build();
        // System.out.println("查询用户名所得密码为"+stu.getPassword()+" 上传密码为"+tmpPwd);
        //System.out.println("两者比较结果为"+tmpPwd.trim().equals(stu.getPassword().trim()));

        if (tmpPwd.trim().equals(student.getPassword().trim())) {
            /*
             * 跟新登录时间，方便督学功能
             * */
            student.setRecent_login(DateUtil.getCurrentTime());
            studentService.update(student);
            /*
             *
             * */
            return Response.builder().status(STATUS.SUCCESS).data(student).cookie(JWTUtil.sign(username, tmpPwd)).build();
//            res.put("code", 200);
//            res.put("cookie", JWTUtil.sign(username, tmpPwd));
//            res.put("data", stu);
//            return res;
        }
        return Response.builder().status(STATUS.BAD_REQUEST).build();
    }

    /*
     * 初次登录更新
     * */
    @RequestMapping(value = "/setfirst/{exam_id}", method = {RequestMethod.GET})
    public Response setfirst(@PathVariable("exam_id") String exam_id) {
        HashMap<String, Object> res = new HashMap<>();
        Student student = Student.builder().build();
        student.setIs_first(1);
        student.setExam_id(exam_id);
        if (studentService.update(student) == 1)
//        {
//            res.put("code", 200);
//            res.put("data", "更新初次登录状态成功");
//            return res;
            return Response.builder().status(STATUS.SUCCESS).message("更新初次登录状态成功").build();
//        } else {
//            res.put("code", 400);
//            res.put("data", "更新初次登录状态失败");
//            return res;
//        }
        return Response.builder().status(STATUS.BAD_REQUEST).message("更新初次登录状态失败").build();
    }

    //course/1
    /*
     * 课程信息请求
     * */
    @RequestMapping(value = "/course/{exam_id}", method = {RequestMethod.GET})
    public Response getCourses(@PathVariable("exam_id") String exam_id) {
        List<StuCourse> stuCourses = stuCourseService.getById(exam_id);
        if (stuCourses.size() != 0) {
//            res.put("code", 200);
//            res.put("data", stuCourses);
//            return res;
            return Response.builder().status(STATUS.SUCCESS).data(stuCourses).build();
        }
//        res.put("code", 200);
//        res.put("data", stuCourses);
//        return res;
        return Response.builder().status(STATUS.BAD_REQUEST).build();
    }

    /*
     * 更新课程信息
     * */
    @RequestMapping(value = "/stucourse", method = {RequestMethod.PUT})
    public Response update(@RequestBody JSONObject jsonParam) {
      /*  SerializeConfig config = new SerializeConfig();
        config.setSerializeFilters((ValueFilter) (object, name, value) -> {
            if (value== null) {
                return null;
            }
            //TODO 在这里还可以干更多事情
            return value;
        });*/
        StuCourse stucourse = JSONObject.parseObject(jsonParam.toJSONString(), StuCourse.class);
//        System.out.println(stucourse.toString());
        if ((stuCourseService.update(stucourse) == 1))
            return Response.builder().status(STATUS.SUCCESS).build();
        return Response.builder().status(STATUS.BAD_REQUEST).build();
//        if (stuCourseService.update(stucourse) == 1) {
//            res.put("code", 200);
//            res.put("data", "update success");
//            return res;
//        } else {
//            res.put("code", 400);
//            res.put("data", "update fail");
//            return res;
//        }
    }

    // @RequestMapping(value="/catalog",method)

    /*
     * 获取通知
     * */
    @RequestMapping(value = "/notice", method = {RequestMethod.GET})
    public Response getNotices(@RequestParam("main_school") String main_school, @RequestParam("sub_school") String sub_school,
                               @RequestParam("limit") int limit, @RequestParam("page") int page
            , @RequestParam("type") String type) {
        if (type.trim().equals("any")) {
            int newlimit = (page - 1) * limit;
            int pagesize = limit;
            List<Map<String, Object>> ls = noticeService.getNoticeBySchool(main_school, sub_school, newlimit, pagesize);
            int sum = noticeService.getNoticeSum(main_school, sub_school);
            if (ls.size() > 0) {
//                res.put("code", 200);
//                res.put("data", ls);
//                res.put("totalpage", Math.ceil(sum * 1.0 / page));
//                return res;
                return Response.builder().status(STATUS.SUCCESS).data(ls).total((int) Math.ceil((sum * 1.0) / page)).build();
            } else {
                return Response.builder().status(STATUS.BAD_REQUEST).build();
//                res.put("code", 400);
//                res.put("data", "无数据");
            }
        } else {
            int newlimit = (page - 1) * limit;
            int pagesize = limit;
            HashMap<String, Object> hs = new HashMap<>();
            hs.put("start", newlimit);
            hs.put("pagesize", pagesize);
            hs.put("main_school", main_school);
            hs.put("sub_school", sub_school);
            hs.put("notice_type", type);
            List<Map<String, Object>> ls = noticeService.getNoticesWirthType(hs);
//            res.put("code", 200);
//            res.put("data", ls);
            return Response.builder().status(STATUS.SUCCESS).data(ls).build();
        }
    }

    /*
     * 获取单个通知
     * */
    @RequestMapping(value = "/notice/{notice_id}", method = {RequestMethod.GET})
    public Response getById(@PathVariable("notice_id") int notice_id) {
        Notice notice = noticeService.getById(notice_id);
        return Response.builder().status(STATUS.SUCCESS).data(notice).build();
//        res.put("code", 20000);
//        res.put("data", notice);
//        return res;
    }

    /*
     * 更改密码
     * */
    @RequestMapping(value = "/changepw", method = {RequestMethod.PUT})
    public Response changepw(@RequestBody JSONObject jsonParam) {
        HashMap<String, Object> params = JSONObject.parseObject(jsonParam.toJSONString(), new TypeReference<HashMap<String, Object>>() {
        });
        String exam_id = (String) params.get("exam_id");
        String new_password = (String) params.get("newpassword");
        Student stu = Student.builder().build();
        stu.setExam_id(exam_id);
        stu.setPassword(new_password);
        if (studentService.update(stu) == 1)
//        {
//            res.put("code", 200);
//            res.put("data", "change password success");
//            return res;
            return Response.builder().status(STATUS.SUCCESS).message("更改密码成功").build();
//        } else {
//            res.put("code", 400);
//            res.put("data", "change password fail");
//            return res;
//        }
        return Response.builder().status(STATUS.BAD_REQUEST).build();
    }


    /*
     * 更新个人信息
     * */
    @RequestMapping(value = "/updatestu", method = {RequestMethod.PUT})
    public Response updatestu(@RequestBody JSONObject jsonParam) {
        Student stu = JSONObject.parseObject(jsonParam.toJSONString(), Student.class);
        if (studentService.update(stu) == 1)
            return Response.builder().status(STATUS.SUCCESS).message("更新个人信息成功").build();
        return Response.builder().status(STATUS.BAD_REQUEST).build();

//        {
//            res.put("code", 200);
//            res.put("data", "change password success");
//            return res;
//        } else {
//            res.put("code", 400);
//            res.put("data", "change password fail");
//            return res;
//        }
//        {
//            res.put("code", 200);
//            res.put("data", "change success");
//            return res;
//        } else {
//            res.put("code", 400);
//            res.put("data", "change  fail");
//            return res;
//        }
    }

    /*
     * 获取学校信息
     * */
    @RequestMapping(value = "/school", method = {RequestMethod.GET})
    public Response getSchoolInfo(@RequestParam("main_school") String main_school, @RequestParam("sub_school") String sub_school) {
        School school = schoolService.getSchool(main_school, sub_school);
        if (school != null)
//        {
            return Response.builder().status(STATUS.SUCCESS).data(school).build();
        return Response.builder().status(STATUS.BAD_REQUEST).message("无该学校").build();
//        if (school == null) {
//            res.put("code", 400);
//            res.put("data", "无该学校");
//            return res;
//        } else {
//            res.put("code", 200);
//            res.put("data", school);
//            return res;
//        }
    }


    /*
     * 活体监测
     * */
    @RequestMapping(value = "/detect", method = {RequestMethod.POST})
    public Response detect(@RequestParam("File") MultipartFile
                                   imgFile, @RequestParam("exam_id") String exam_id, @RequestParam("course_id") String course_id,
                           @RequestParam("is_test") int is_test) {
        try {
            //File imgfile = FileUtil.getFile(exam_id);
            //String avatarbs64 = FileUtil.byteConverterBASE64(imgfile);
            //File tmpfile = MultipartFileToFile.multipartFileToFile(imgFile);
            //String videobs64 = FileUtil.byteConverterBASE64(tmpfile);
            String videobs64 = FileUtil.getBase64FromInputStream(imgFile.getInputStream());
            System.out.println("开始请求token " + "，开始请求时间为：" + new Date());
            RestTemplate restTemplate = new RestTemplate();
            String access_token = LivenessUtil.getToken();
            System.out.println("开始请求token " + "，开始请求时间为：" + new Date());
            System.out.println("token is" + access_token);
            if (access_token.equals("")) {
//                res.put("code", 400);
//                res.put("data", "获取百度人脸识别token失败");
//                return res;
                return Response.builder().status(STATUS.BAD_REQUEST).data("获取百度人脸识别token失败").message("获取百度人脸识别token失败").build();
            }
            //MultiValueMap<String, Object> map = new LinkedMultiValueMap<>();
            HttpHeaders headers = new HttpHeaders();
            //map.add("access_token", access_token);
            headers.add("Content-Type", "application/x-www-form-urlencoded");
            MultiValueMap<String, String> requestBody = new LinkedMultiValueMap<>();
            requestBody.add("video_base64", videobs64);
            HttpEntity<MultiValueMap> requestEntity = new HttpEntity<MultiValueMap>(requestBody, headers);
            String request_url = verifyurl + "?access_token=" + access_token;
            //SimpleDateFormat df1 = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
            System.out.println("request url is " + request_url + "，开始请求时间为：" + new Date());
            ResponseEntity<String> responseEntity = restTemplate.postForEntity(request_url, requestEntity, String.class);
            System.out.println("request url is " + request_url + "，开始请求时间为：" + new Date());
            String result = responseEntity.getBody();
            System.out.println(result);
            double score = LivenessUtil.getScore_v2(result);
            if (score <= 0.393241) {
//                res.put("code", 400);
//                res.put("data", "活体检测失败，判别结果为非活体");
//                return res;
                return Response.builder().data("活体检测失败，判别结果为非活体").status(STATUS.SUCCESS).build();
            }
            //从百度接口返回的图片中，存抓取到的图片
            File fileDir = UploadUtil.getImgDirFile();
            String pic = LivenessUtil.getPic_v2(result);
            System.out.println("baidu pic is " + pic);
            String uuid = UUID.randomUUID().toString().replaceAll("-", "");
            SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd-HH-mm-ss");
            String date = df.format(new Date());
            String catch_name = date + "_" + uuid + ".jpg";
            String CatchFilePath = fileDir.getAbsolutePath() + File.separator + date + "_" + uuid + ".jpg";
            //UploadUtils.writeFile(pic,CatchFilePath);
            /*
            if(is_test!=0){
                String phaseCatch = stuCourseService.getPhaseCatch(exam_id,course_id);
                if(phaseCatch==null){
                    JSONArray phaseArray = new JSONArray();
                    JSONObject ph1= new JSONObject();
                    ph1.put("phase1","");
                    JSONObject ph2= new JSONObject();
                    ph2.put("phase2","");
                    JSONObject ph3= new JSONObject();
                    ph3.put("phase3","");
                    JSONObject ph4= new JSONObject();
                    ph4.put("phase4","");
                    JSONObject ph5= new JSONObject();
                    ph4.put("phase5","");
                    phaseArray.add(ph1);
                    phaseArray.add(ph2);
                    phaseArray.add(ph3);
                    phaseArray.add(ph4);
                    phaseArray.add(ph5);
                    phaseCatch=phaseArray.toJSONString();
                }
                System.out.println("phase catchpath is " + CatchFilePath);
                UploadUtils.writeFile(pic, CatchFilePath);
                JSONObject updatephase=new JSONObject();
                updatephase.put("phase"+is_test,uuid);
                JSONArray oldphase = JSONArray.parseArray(phaseCatch);
                oldphase.set(is_test-1,updatephase);
                StuCourse stucourse = new StuCourse();
                stucourse.setExam_id(exam_id);
                stucourse.setCourse_id(course_id);
                stucourse.setPhase_catch(oldphase.toJSONString());
                stuCourseService.update(stucourse);
            }
            */
            if (is_test != 0) {
                String phaseCatch = stuCourseService.getPhaseCatch(exam_id, course_id);
                if (phaseCatch == null) {
                    phaseCatch = "";
                }
                String[] phaselist = phaseCatch.split("#");
                if (phaselist.length < 7)
                    phaseCatch = phaseCatch + "#" + catch_name;
                else {
                    phaselist[1] = catch_name;
                    phaseCatch = BaseUtils.concat(phaselist);
                }
                //UploadUtils.writeFile(pic, CatchFilePath);
                ImageTranscodeUtil.CreateImg(pic, CatchFilePath);
                StuCourse stuCourse = StuCourse.builder().build();
                stuCourse.setExam_id(exam_id);
                stuCourse.setCourse_id(course_id);
                stuCourse.setPhase_catch(phaseCatch);
                stuCourseService.update(stuCourse);
            }

            if (is_test == 0) {

                //如果不是考试抓拍，就需要获取原有的study_catch
                String study_catch = stuCourseService.getStudyCatch(exam_id, course_id);
                //数据库中，study_catch默认为空，如果是第一次，那需要进行初始化的处理
                if (study_catch == null) {
                    study_catch = "";
                }
                int num = BaseUtils.appearNumber(study_catch, "#");
                //如果已经存了6张截图，那就不再继续存了，如果是阶段测评，也不存study_catch的截图
                if (num < 6 && !course_id.equals("-1")) {
                    System.out.println("catchpath is " + CatchFilePath);
                    //UploadUtils.writeFile(pic, CatchFilePath);
                    ImageTranscodeUtil.CreateImg(pic, CatchFilePath);
                    String new_catch = study_catch + "#" + catch_name;
                    StuCourse stucourse = StuCourse.builder().build();
                    stucourse.setExam_id(exam_id);
                    stucourse.setCourse_id(course_id);
                    stucourse.setStudy_catch(new_catch);
                    stuCourseService.update(stucourse);
                }
            }

            //获取用于图像识别对比的学生文件
            File imgfile = FileUtil.getFile(exam_id);
            String avatarbs64 = FileUtil.getBase64FromInputStream(new FileInputStream(imgfile));


            JSONArray jsonarray = new JSONArray();
            JSONObject json1 = new JSONObject();
            JSONObject json2 = new JSONObject();
            json1.put("image", pic);
            json1.put("image_type", "BASE64");
            json1.put("face_type", "LIVE");
            json1.put("quality_control", "NONE");
            json1.put("liveness_control", "NONE");
            jsonarray.add(json1);
            json2.put("image", avatarbs64);
            json2.put("image_type", "BASE64");
            json2.put("face_type", "LIVE");
            json2.put("quality_control", "NONE");
            json2.put("liveness_control", "NONE");
            jsonarray.add(json2);
            HttpHeaders matchheaders = new HttpHeaders();
            matchheaders.add("Content-Type", "application/json");
            HttpEntity<String> formEntity = new HttpEntity<>(jsonarray.toString(), matchheaders);
            String RequestMatchUrl = matchurl + "?access_token=" + access_token;
            System.out.println("RequestMatchUrl is " + RequestMatchUrl);
            String s = restTemplate.postForEntity(RequestMatchUrl, formEntity, String.class).getBody();
            System.out.println(s);
            Double match_ret = LivenessUtil.getMatchScore(s);
            if (match_ret != null) {
                if (match_ret > 60)
                    return Response.builder().status(STATUS.SUCCESS).data("人脸验证通过，验证分数为" + match_ret).build();
                return Response.builder().status(STATUS.BAD_REQUEST).data("人脸验证未通过，验证分数为" + match_ret).build();

//                {
//                    res.put("code", 200);
//                    res.put("data", "人脸验证通过，验证分数为" + matchres);
//                    return res;
//                } else {
//                    res.put("code", 400);
//                    res.put("data", "人脸验证未通过，验证分数为" + matchres);
//                    return res;
//                }

            } else {
//                res.put("code", 400);
//                res.put("data", "人脸识别出现未知错误");
//                return res;
                return Response.builder().status(STATUS.BAD_REQUEST).data("人脸识别出现未知错误").build();

            }


        } catch (Exception e) {
            e.printStackTrace();
            return Response.builder().status(STATUS.BAD_REQUEST).data(e.getMessage()).message(e.getMessage()).build();

        }
    }

    /*
     *保利威视token
     * */
    @RequestMapping(value = "/getPolyToken", method = {RequestMethod.POST})
    public Response getPolyToken(@RequestBody JSONObject jsonParam) {
        HashMap<String, String> params = JSONObject.parseObject(jsonParam.toJSONString(), new TypeReference<HashMap<String, String>>() {
        });
        String userId = "d6001adfae";
        String secretkey = "00X97pOUEx";
        String ts = String.valueOf(System.currentTimeMillis());

        String videoId = params.get("videoId");
        String viewerIp = params.get("viewerIp");
        String viewerId = params.get("viewerId");
        String viewerName = params.get("viewerName");
        String extraParams = "HTML5";
        System.out.println(videoId + "|" + viewerIp + "|" + viewerId + "|" + viewerName);

        String concat = "extraParams" + extraParams + "ts" + ts + "userId" + userId + "videoId" + videoId + "viewerId"
                + viewerId + "viewerIp" + viewerIp + "viewerName" + viewerName;
        String plain = secretkey + concat + secretkey;
        String sign = DigestUtils.md5Hex(plain).toUpperCase();
        MultiValueMap<String, String> map = new LinkedMultiValueMap<>();
        map.add("userId", userId);
        map.add("videoId", videoId);
        map.add("ts", ts);
        map.add("viewerIp", viewerIp);
        map.add("viewerName", viewerName);
        map.add("extraParams", extraParams);
        map.add("viewerId", viewerId);
        map.add("sign", sign);
        HttpHeaders headers = new HttpHeaders();
        headers.add("Content-Type", "application/x-www-form-urlencoded");
        HttpEntity<MultiValueMap<String, String>> request = new HttpEntity<>(map, headers);
        RestTemplate restTemplate = new RestTemplate();
        ResponseEntity<String> response = restTemplate.postForEntity(polyToken, request, String.class);
        JSONObject jsonObject = JSONObject.parseObject(response.getBody());
        int code = jsonObject.getInteger("code");
        String token;
        if (code == 200) {
            JSONObject tmp = jsonObject.getObject("data", JSONObject.class);
            token = tmp.getString("token");
//            System.out.println(token);
//            res.put("code", 200);
//            res.put("data", token);
            return Response.builder().status(STATUS.SUCCESS).data(token).build();
        } else {
            return Response.builder().status(STATUS.BAD_REQUEST).data("token未获取成功").build();
//            res.put("code", 400);
//            res.put("data", "token未获取成功");
        }
//        return res;
    }

    /*
     * 获取客户端ip
     * */
    @RequestMapping(value = "/getClientIp", method = {RequestMethod.GET})
    public Response getClientIp(HttpServletRequest request) {
        String ip = request.getRemoteAddr();
//        res.put("code", 20000);
//        res.put("data", ip);
//        return res;
        return Response.builder().status(STATUS.SUCCESS).data(ip).build();
    }

    /*
     * 试卷获取
     * */
    @RequestMapping(value = "/stuexam", method = {RequestMethod.GET})
    public Response getStuExam(@RequestParam("exam_id") String
                                       exam_id, @RequestParam("course_id") String course_id, @RequestParam("exam_type") int exam_type) {
        StuExam stuexam = StuExam.builder().build();
        stuexam.setExam_type(exam_type);
        stuexam.setExam_id(exam_id);
        stuexam.setCourse_id(course_id);
        StuExam resExam = stuExamMapper.selectByPrimaryKey(stuexam);
        if (resExam == null)
            return Response.builder().status(STATUS.BAD_REQUEST).message("未能查询到学校").build();
        return Response.builder().status(STATUS.SUCCESS).data(resExam).build();
//        {
//            res.put("code", 400);
//            res.put("data", "未能查询到学校");
//        }
//        res.put("code", 200);
//        res.put("data", resExam);
//        return res;
    }


    /*
     * 试卷更新模块
     * */
    @RequestMapping(value = "/stuexam", method = {RequestMethod.POST})
    public Response updateStuExam(@RequestParam("exam_id") String
                                          exam_id, @RequestParam("course_id") String course_id, @RequestParam("exam_type") int exam_type,
                                  @RequestBody JSONObject jsonParam) {
        System.out.println(jsonParam);
        StuExam stuexam = StuExam.builder().build();
        stuexam.setCourse_id(course_id);
        stuexam.setExam_id(exam_id);
        stuexam.setExam_type(exam_type);
        stuexam.setExam_content((String) jsonParam.get("content"));
        if (stuExamMapper.updateByPrimaryKey(stuexam) == 1)
            return Response.builder().status(STATUS.SUCCESS).data("更新成功").build();
        return Response.builder().status(STATUS.BAD_REQUEST).data("更新失败").build();
//        {
//            res.put("code", 200);
//            res.put("data", "更新成功");
        //return res;
//        } else {
//            res.put("code", 400);
//            res.put("code", "更新失败");
//        }
//        return res;
    }

    /*
     * 重考api
     * */
    @RequestMapping(value = "/origin_exam", method = {RequestMethod.GET})
    public Response getOriginExam(@RequestParam("course_id") String
                                          course_id, @RequestParam("exam_type") Integer exam_type) {
        HashMap<String, Object> hs = new HashMap<>();
        hs.put("course_id", course_id);
        hs.put("exam_type", exam_type);
        Examination examination = examinationService.getExamByTypeId(hs);
        if (null != examination)
            return Response.builder().status(STATUS.SUCCESS).data(examination).build();
        return Response.builder().status(STATUS.BAD_REQUEST).message("试卷不存在").build();
//        {
//            res.put("code", 20000);
//            res.put("data", examination);
//        } else {
//            res.put("code", 400);
//            res.put("data", "不存在");
//        }
//
//        return res;
    }

    /*
     * 获取可访问IP列表
     * */
    @RequestMapping(value = "/getip", method = {RequestMethod.GET})
    public Response getips(@RequestParam("main_school") String
                                   main_school, @RequestParam("sub_school") String sub_school) {
        HashMap<String, Object> hs1 = new HashMap<>();
        hs1.put("main_school", main_school);
        hs1.put("sub_school", sub_school);
        List<Ip> ips = ipService.getAllowIp(hs1);
//        res.put("code", 200);
//        res.put("data", ips);
//        return res;
        return Response.builder().status(STATUS.SUCCESS).data(ips).build();
    }

}
